<template>
  <div>
    <FormNavbar
      :title="navbar_title"
      :buttons="buttons"
      :hasActive="hasActive"
      :editable="editable"
      :record="record"
      @click-left="onClickLeft"
      @click-right="onClickRight"
    />

    <OToolbar
      :editable="editable"
      :current-state="current_state"
      :states="header_statusbar_visible"
      :buttons="header_buttons"
      @button-clicked="handleBtnClicked"
    />

    <a-divider />

    <template v-if="!editable">
      <!-- 三个专用功能按钮 -->
      <template v-if="['in_invoice', 'in_refund'].includes(record.type)">
        <a-button size="small"> OCR 识别 </a-button>
        <a-button size="small"> 查验 </a-button>
      </template>
      <template v-if="['out_invoice', 'out_refund'].includes(record.type)">
      </template>
    </template>

    <div>
      <div>发票类型: {{ { ...record, ...values }.type }}</div>
      <div>订单号码: {{ { ...record, ...values }.name }}</div>

      <div>
        下载:
        <OField
          :field-info="{ ...meta_get('attachment_id') }"
          :view-info="viewInfo"
          :data-info="dataInfo"
        />

        <!-- <div>
          <FormField
            field-name="attachment_id"
            width="120px"
            v-model="formValues"
            :editable="res_id ? editable : false"
            :fields="fields"
            :view-info="viewInfo"
            :data-info="dataInfo"
            @change="handleChange"
          />
        </div> -->
      </div>

      <FormField
        field-name="company_id"
        width="300px"
        v-model="formValues"
        :editable="editable"
        :fields="fields"
        :view-info="viewInfo"
        :data-info="dataInfo"
        @change="handleChange"
      />
    </div>

    <FapiaoPage
      ref="refForm"
      :model.sync="formValues"
      :rules="rules_edit"
      :editable="editable"
      :fields="fields"
      :view-info="viewInfo"
      :data-info="dataInfo"
      @change="handleChange"
    />
  </div>
</template>

<script>
import formMixin from '@/odooui/formMixin'
import FormNavbar from '@/components/ONavbar/formNavbar.vue'
import OToolbar from '@/components/OToolbar/index.vue'

import FapiaoPage from './fapiao_page.vue'
import FormField from '@/components/OView/FormField.vue'

// import OField from '@/components/OField/OField.vue'

export default {
  name: 'FormView',
  components: { FormNavbar, OToolbar, FapiaoPage, FormField },

  mixins: [formMixin],

  props: {},

  data() {
    return {}
  },
  computed: {},

  watch: {},

  created() {},

  mounted() {},

  methods: {
    onClickLeft() {
      if (this.editable) {
        this.onClickCancel()
      } else {
        this.onClickBack()
      }
    },

    onClickRight(btn) {
      const btn_fns = {
        save: 'onClickSave',
        edit: 'onClickEdit',
        new: 'onClickNew',
        del: 'onClickDel',
        unlink: 'onClickDel',
        copy: 'handleOnCopy',
        archive: 'handleOnArchive',
        unarchive: 'handleOnUnarchive'
      }

      this[btn_fns[btn]]()
    }
  }
}
</script>

<style scoped></style>
